/*Copyright*/
package com.jmetest.physics;

import com.jme.math.Vector3f;
import com.jme.scene.Text;
import com.jme.scene.shape.Box;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.util.SimplePhysicsGame;

/**
 * @author forum user sbayless
 */
public class TestCenter extends SimplePhysicsGame {

    protected void simpleInitGame() {
        StaticPhysicsNode staticNode = getPhysicsSpace().createStaticNode();
        rootNode.attachChild( staticNode );

        final Box visualFloorBox = new Box( "floor", new Vector3f(), 5, 0.25f, 5 );
        staticNode.attachChild( visualFloorBox );
        staticNode.generatePhysicsGeometry();

        DynamicPhysicsNode dynamicNode = getPhysicsSpace().createDynamicNode();
        rootNode.attachChild( dynamicNode );

        final Box visualFallingBox = new Box( "falling box", new Vector3f(), 0.5f, 0.5f, 0.5f );
        visualFallingBox.getLocalTranslation().set(-4,0,0);  //make the box off centered

        dynamicNode.attachChild( visualFallingBox );

        dynamicNode.generatePhysicsGeometry();

        dynamicNode.setCenterOfMass(new Vector3f(-4,0,0));  //set the center of mass to correct for the off center box
        dynamicNode.computeMass();

        dynamicNode.getLocalTranslation().set( 0, 5, 0 );

        showPhysics = true;

        Text label = Text.createDefaultTextLabel( "info", "The box should behave 'normally' as the center of mass " +
                "was moved into the center of the box again." );
        label.setLocalTranslation( 0, 20, 0 );
        fpsNode.attachChild( label );
    }

    public static void main( String[] args ) {
        new TestCenter().start();
    }
}

/*
 * $Log: not supported by cvs2svn $
 */

